package com.youlu.campus.web.order.service;

import com.youlu.campus.web.common.base.RequestContext;
import com.youlu.campus.web.order.entity.OrderPO;
import com.youlu.campus.entity.VO.PlaceOrderReq;
import com.youlu.campus.entity.UserPO;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zgz
 * @date 2020/8/31 14:22
 */

@Service
@Slf4j
public class PaperCertificateOrderService extends OrderBaseService {
    final public static String payCache = "luyou.pay-cache";

    @Override
    public Map<String, String> placeOrder(PlaceOrderReq req) {
        UserPO user = RequestContext.getCurUser();
        //获取订单信息
        OrderPO orderPO = super.saveStandardOrder(user, super.checkGoods(user, req), super.checkAddress(req.getAddressId()), req);
        Map<String, String> result = new HashMap<>();
        //获取预支付参数
        QResult<Map<String, String>> uniOrderResult = super.getUniOrderResult(orderPO);
        if (uniOrderResult.code == 0) {
            result = uniOrderResult.data;
            redisTemplate.opsForHash().put(payCache,"ca",orderPO.getOrderNo());
            log.info("placeOrder applyReq {} result {}", req, result);
        } else {
            log.info("placeOrder applyReq {} error msg {}", req, uniOrderResult.msg);
        }
        return result;
    }

    @Override
    public boolean handlePayNotify(OrderPO orderPO) {
        //处理证书支付时间
        return true;
    }
}
